package mobi.hami.huapin.service.impl;

import com.github.pagehelper.PageHelper;
import mobi.hami.huapin.dao.NoteSortMapper;
import mobi.hami.huapin.dto.NoteSortForUserDTO;
import mobi.hami.huapin.model.NoteSort;
import mobi.hami.huapin.model.NoteSortExample;
import mobi.hami.huapin.model.OpinionLeader;
import mobi.hami.huapin.service.NoteSortService;
import mobi.hami.huapin.util.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Create by 小峰 on 2018/9/13.
 * 纸条分类
 */
@Service
public class NoteSortServiceImpl implements NoteSortService {

    @Autowired
    private NoteSortMapper sortMapper;

    /**
     * 前台获取分类（只获取启用的）
     *
     * @return
     */
    @Override
    public List<NoteSortForUserDTO> querySortForUser() {

        NoteSortExample example = new NoteSortExample();
        NoteSortExample.Criteria  criterion=example.createCriteria();
        criterion.andStatusEqualTo(1);
        criterion.andOnline_timeLessThan(new Date());
        example.setOrderByClause("order_num asc");
        PageHelper.startPage(1,10);
        List<NoteSort> list = sortMapper.selectByExample(example);

        List<NoteSortForUserDTO> noteSortForUserDTOS = new ArrayList<>();
        list.forEach(a->{

            NoteSortForUserDTO sort = new NoteSortForUserDTO();
            BeanUtil.copyProperties(a,sort);
            noteSortForUserDTOS.add(sort);

        });

        return noteSortForUserDTOS;
    }
}
